package com.seeyon.ctp.rest.resources;


import com.seeyon.apps.taxFund.manager.GKInvoiceManager;
import com.seeyon.cap4.form.exception.FormException;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.exceptions.BusinessException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Map;

@Path("gk/invoice")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces(MediaType.APPLICATION_JSON)
public class GKInvoiceResource extends BaseResource {

	private static final Logger logger = LoggerFactory.getLogger(GKInvoiceResource.class);

    private GKInvoiceManager gkInvoiceManager = (GKInvoiceManager) AppContext.getBean("gkInvoiceManager");
	
	@POST
	@Produces({ MediaType.APPLICATION_JSON })
	@Path("receive")
	public Response receive(List<Map<String, Object>> params){
        try {
            logger.info("【税金-发票回写接口】请求参数：【{}】", com.seeyon.ctp.util.json.JSONUtil.toJSONString(params));
            gkInvoiceManager.receiveInvoice( params);
            return success("成功");
        }catch (BusinessException | IllegalArgumentException | FormException e) {
            logger.error("【税金-发票回写接口】接口异常", e);
            return fail(e.getMessage());
        }catch (Exception e) {
            logger.error("【税金-发票回写接口】服务异常", e);
            return fail("服务异常");
        }
    }

    @GET
    @Path("productSync")
    public Response productSync(){
        try {
            gkInvoiceManager.productSync();
            return success("成功");
        }catch (BusinessException | IllegalArgumentException | FormException e) {
            logger.error("【税金-发票回写接口】接口异常", e);
            return fail(e.getMessage());
        }catch (Exception e) {
            logger.error("【税金-发票回写接口】服务异常", e);
            return fail("服务异常");
        }
    }
}
